package Accessors;

import Callbacks.AbstractCallback;
import Models.Brew;
import Presenter.BrewPresenter;
import android.app.ProgressDialog;
import android.content.Context;

@SuppressWarnings("rawtypes")
public class BrewAccessor extends AbstractAccessor<Brew,BrewPresenter,AbstractCallback> {
	private final String NAME = "brews";
	private final String DIALOG = "Brew";
	
	private final static BrewPresenter presenter = new BrewPresenter();
	
	//Modal dialog variable.
	ProgressDialog modalDialog = null;
	
	public BrewAccessor(AbstractCallback callback){
		super(presenter, callback);
	}
	
	//Public access functions.
	public void getAllItems(final Context context){
		String dialog = "Loading " + DIALOG + " List...";
		String rfString = NAME;
		super.getAllItems(context, dialog, rfString);
	}
	
	public void getPackageableBrews(final Context context){
		String dialog = "Loading " + DIALOG + " List...";
		String rfString = NAME + "/runQuery/SELECT b FROM Brews b WHERE b.bState='15' AND b.volLeft>'0'";
		rfString = rfString.replaceAll(" ", "%20");
		super.getAllItems(context, dialog, rfString);
	}
	
	public void getUnPackagedBrews(final Context context){
		String dialog = "Loading " + DIALOG + " List...";
		String rfString = NAME + "/runQuery/SELECT b FROM Brews b WHERE b.bState<'20' OR b.bState='25'";
		rfString = rfString.replaceAll(" ", "%20");
		super.getAllItems(context, dialog, rfString);
	}
	
	public void getMoveableBrews(final Context context){
		String dialog = "Loading " + DIALOG + " List...";
		String rfString = NAME + "/runNamedQuery/Brews.findInProcess";
		super.getAllItems(context, dialog, rfString);
	}
	
	public void getSplittableBatches(final Context context){
		String dialog = "Loading " + DIALOG + " List...";
		String rfString = NAME + "/getSplittableBatches";
		super.getAllItems(context, dialog, rfString);
	}
	
	public void getPlannedBrews(final Context context){
		String dialog = "Loading " + DIALOG + " List...";
		String rfString = NAME + "/runQuery/SELECT b FROM Brews b WHERE b.bState<'5'";
		rfString = rfString.replaceAll(" ", "%20");
		super.getAllItems(context, dialog, rfString);
	}
	
	public void getItem(final int id, final Context context){
		String dialog = "Loading " + DIALOG + "...";
		String rfString = NAME + "/" + Integer.toString(id);
		super.getItem(context, dialog, rfString);
	}
	
	public void doItemUpdate(final Brew item, final Context context){
		String dialog = "Updating " + DIALOG + "...";
		String rfString = NAME;
		super.doItemUpdate(item, context, dialog, rfString);
	}
	
	public void doBatchSplit(final Brew item, final Context context
			, final int vesselID, final int beerID, final double volume){
		String dialog = "Updating " + DIALOG + "...";
		String rfString = NAME + "/doBatchSplit/" + Integer.toString(vesselID) 
				+ "/" + Integer.toString(beerID) + "/" + Double.toString(volume);
		super.doItemUpdate(item, context, dialog, rfString);
	}
	
	public void updateBrewServerSide(final Brew item, final Context context){
		String dialog = "Updating " + DIALOG + "...";
		String rfString = NAME + "/processBrewUpdate";
		super.doItemUpdate(item, context, dialog, rfString);
	}
	
	public void doItemInsert(final Brew item, final Context context){
		String dialog = "Inserting " + DIALOG + "...";
		String rfString = NAME;
		super.doItemInsert(item, context, dialog, rfString);
	}
}
